<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        th{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<label style="color:#000;font-size: 15px;">今日销售额为：{$count}元</label>
<div style="float: right; margin-top: 5px;margin-bottom: 5px" class="box-title ">

    <form class="form-inline" action="{:url('index/orders/purchase')}" method="get">
        <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
            <input type="text" style="text-align: center" class="layui-input" id="start" name="start"
                   value="<?php if(isset($date)){ echo $date;}else{ echo $start;}?>"/>
        </div>
        -
        <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
            <input type="text" style="text-align: center"  class="layui-input" id="end" name="end" value="<?php if(isset($date)){ echo $date;}else{echo $end;}?>"/>

        </div>
        <input type="hidden" name="sid" value="{$sid}"/>
        <input type="text" name="title" value="<?php if(isset($title)) echo $title ?>" class="form-control" id="exampleInputEmail3" >

        <input type="submit" class="btn btn-default" value="搜索"/>
        <input type="button" onclick="res({$sid})" value="全部显示" class="btn btn-default"/>
    </form>
</div>
<table class="table table-bordered" style="width: 1300px;margin: 0 auto">
    <tr>
        <th>订单号</th>
        <th>下单时间</th>
        <th>备注</th>
        <th>操作</th>
    </tr>
    {foreach $result as $val}
    <tr id="del{$val.id}" style="text-align: center">
        <td>{$val.ordernumber}</td>
        <td>{$val.date}</td>
        <td>{$val.remarks}</td>
        <td>
            <button type="button" class="btn btn-warning btn-xs" onclick="remarks({$val.ordernumber})">添加备注</button>
            <button onclick="detail({$val.ordernumber},{$sid})" type="button" class="btn btn-info btn-xs" >订单详情</button>
        </td>
    </tr>
    {/foreach}
</table>
<div style="margin-left: 30px">{$result->render()}</div>
</body>
<script>
    //订单详情
    function detail(ordernumber,sid) {
        window.location.href = "{:url('index/orders/detail')}?sid="+sid+"&ordernumber="+ordernumber;
    }
    //查看全部
    function res(sid) {
        window.location.href = "{:url('index/orders/purchase')}?sid="+sid;
    }
    // 添加备注
    function remarks(ordernumber) {
        layer.prompt({
            formType: 2,
            title: '备注',
            area: ['300px', '200px'] //自定义文本域宽高
        }, function(value, index, elem){
            $.ajax({
                url:"{:url('index/orders/remarks')}",
                data:{
                    'ordernumber':ordernumber,
                    'remarks':value
                },
                type:"post",
                dataType:"json",
                success:function (res) {
                    if(res.success){
                        layer.msg(res.success,{icon:1,time:2000},function () {
                            window.location.reload();
                        });
                    }else if(res.error) {
                        layer.msg(res.error,{icon:5,time:2000});
                    }
                }
            });
            layer.close(index);
        });
    }
    //时间
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        laydate.render({
            elem: '#end' //指定元素
        });
    });

</script>
</html>